#pragma once
#include "../../third/include/aip-cpp-sdk/speech.h"
#include "../logger.hpp"
#include <memory>
#include <string>
 
namespace shared {

namespace infra {

class ASRClient
{
public:
    ASRClient(const std::string& appId, const std::string& apiKey, const std::string& secretKey)
        : client_(appId, apiKey, secretKey) {}

    std::string recognize(const std::string& speechData, std::string& errMsg)
    {
        Json::Value ret = client_.recognize(speechData, "pcm", 16000, aip::null);
        if(ret["err_no"].asInt()) {
            errMsg = ret["err_msg"].asString();
            LOG_ERROR("语音识别异常: {}", errMsg);
            return std::string();
        }
        return ret["result"][0].asString();
    }
private:
    aip::Speech client_;
};

using ASRClientPtr = std::shared_ptr<ASRClient>;

}}

